package com.example.service.impl;

import com.example.domain.Student;
import com.example.mapper.StudentMapper;
import com.example.service.StudentService;
import org.apache.ibatis.annotations.MapKey;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

/**
 * @Author: WJ
 * @CreateTime: 2025-04-23  16:28
 * @Description: TODO
 * @Version: 1.0
 */
@Service
public class StudentServiceImpl implements StudentService {
    @Autowired
    private StudentMapper studentMapper;
    /**
     * 获取所有学生信息
     * @return
     */
    public List<Student> getAllStudent() {
        return studentMapper.getAllStudent();
    }

    /**
     * 根据id获取学生信息
     * @param id
     * @return
     */
    @Override
    public Student getStudentById(Long id) {
        return studentMapper.getStudentById(id);
    }

    /**
     * 根据id获取学生成绩
     * @param id
     * @return
     */
    @Override
    public Double getScoreById(Long id) {
        return studentMapper.getScoreById(id);
    }
    /**
     * 根据id获取学生排名
     * @param id
     * @param classId
     * @return
     */
    @Override
    public Integer getRankByIdAndClassId(Long id, Integer classId) {
        return studentMapper.getRankByIdAndClassId(id, classId);
    }
    /**
     * 根据id获取综合信息
     * @param id
     * @return
     */
    @Override
    public List<Map<String, Double>> getComprehensiveInfoById(Long id) {
        if (id == null || id <= 0) {
            throw new IllegalArgumentException("ID 不能为空且必须大于 0");
        }

        List<Map<String, Double>> result = studentMapper.getComprehensiveInfoById(id);

        // 可选：若允许返回空列表而不抛异常，则无需处理 result 是否为空
        return result;
    }

    /**
     *  根据id查询学生课前信息
     * @param id
     * @return
     */
    @Override
    public List<Map<String, Double>> getBeforeClassInfoById(Long id) {
        if (id == null || id <= 0) {
            throw new IllegalArgumentException("ID 不能为空且必须大于 0");
        }
        List<Map<String, Double>> result = studentMapper.getBeforeClassInfoById(id);
        return result;
    }

    /**
     *根据id查询学生课中信息
     * @param id
     * @return
     */
    @Override
    public List<Map<String, Double>> getDuringClassInfoById(Long id) {
        if (id == null || id <= 0) {
            throw new IllegalArgumentException("ID 不能为空且必须大于 0");
        }
        List<Map<String, Double>> result = studentMapper.getDuringClassInfoById(id);
        return result;
    }

    /**
     *根据id查询学生课后信息
     * @param id
     * @return
     */
    @Override
    public List<Map<String, Double>> getAfterClassInfoById(Long id) {
        if (id == null || id <= 0) {
            throw new IllegalArgumentException("ID 不能为空且必须大于 0");
        }
        List<Map<String, Double>> result = studentMapper.getAfterClassInfoById(id);
        return result;
    }

    /**
     * 根据id查询学生进步信息
     * @param id
     * @return
     */
    @Override
    public List<Map<String, Double>> getAdvancedInfoById(Long id) {
        if (id == null || id <= 0) {
            throw new IllegalArgumentException("ID 不能为空且必须大于 0");
        }
        List<Map<String, Double>> result = studentMapper.getAdvancedInfoById(id);
        return result;
    }
    /**
     * 根据id查询学生评语信息
     * @param id
     * @return
     */
    @Override
    public List getRemarkInfoById(Long id) {
        if (id == null || id <= 0) {
            throw new IllegalArgumentException("ID 不能为空且必须大于 0");
        }
        List<String> result = studentMapper.getRemarkInfoById(id);
        return result;
    }
}
